package com.fenghuajueli.idiomppp.ui.fragment.allidiom;

import android.content.Context;

import com.allen.library.RxHttpUtils;
import com.allen.library.bean.BaseData;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.DataObserver;
import com.blankj.utilcode.util.LogUtils;
import com.fenghuajueli.idiomppp.entity.VideoResponseListEntity;
import com.fenghuajueli.idiomppp.net.ApiService;
import com.fenghuajueli.libbasecoreui.mvp.BasePresenter;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class AllStoryPresenter extends BasePresenter<AllStoryView> {


    public AllStoryPresenter(Context mContext) {
        super(mContext);
    }


    public void loadData() {
        getView().showLoading();
        RxHttpUtils.createApi(ApiService.class)
                .getVideoList("iqy_m_217742214")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .compose(Transformer.<BaseData<VideoResponseListEntity>>switchSchedulers())
                .subscribe(new DataObserver<VideoResponseListEntity>() {
                    @Override
                    protected void onError(String errorMsg) {
                        LogUtils.d("访问失败---------------");
                        getView().hideLoading();
                    }

                    @Override
                    protected void onSuccess(VideoResponseListEntity data) {
                        getView().hideLoading();
                        getView().dataLoadSuccess(data.getSearch_lists());
                    }
                });

    }


    public void loadYuYanData() {
        getView().showLoading();
        RxHttpUtils.createApi(ApiService.class)
                .getVideoList("iqy_m_221898214")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .compose(Transformer.<BaseData<VideoResponseListEntity>>switchSchedulers())
                .subscribe(new DataObserver<VideoResponseListEntity>() {
                    @Override
                    protected void onError(String errorMsg) {
                        getView().hideLoading();
                    }

                    @Override
                    protected void onSuccess(VideoResponseListEntity data) {
                        getView().hideLoading();
                        getView().dataLoadSuccess(data.getSearch_lists());
                    }
                });

    }

}
